package lihao2;

public class Test7 {
    public static class Stu {
        int no;
        String name;
        int age;

        Stu(int no, String name, int age) {
            this.no = no;
            this.name = name;
            this.age = age;
        }

        void Add(Stu[] arr) {
            for (int i = 0; i < arr.length; i++)
                arr[i].age += 1;
        }

        void Check(Stu[] arr) {
            for (int i = 0; i < arr.length; i++) {
                if (arr[i].age > 20)
                    System.out.println("学号：" + arr[i].no + "|" + "姓名：" + arr[i].name + "|" + "年龄：" + arr[i].age);
            }
        }

        void Print(Stu[] arr) {
            for (int i = 0; i < arr.length; i++)
                System.out.println("学号：" + arr[i].no + "|" + "姓名：" + arr[i].name + "|" + "年龄：" + arr[i].age);
        }
    }

    public static void main(String[] args) {
        Stu v1 = new Stu(1011, "张三", 18);
        Stu v2 = new Stu(1703, "李四", 19);
        Stu v3 = new Stu(1204, "王五", 20);
        Stu v4 = new Stu(1468, "赵六", 21);
        Stu[] arr = {v1, v2, v3, v4};
        System.out.println("所有学生初始信息如下:");
        v1.Print(arr);
        v1.Add(arr);
        System.out.println("所有学生年龄加一后信息如下:");
        v1.Print(arr);
        System.out.println("年龄大于20的学生名单:");
        v1.Check(arr);

    }
}
